<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : system_power.manage.php   FILE_PATH : E:\web\mulitishop\system\system_power.manage.php
 * 后台权限管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 
 * @package 
 * @subpackage 
 * @version Tue Nov 13 17:40:45 CST 2007
 */

require_once("../global.inc.php");

class SysPowerManage extends SystemFrameWork{
	/**
	 * 权限对象
	 *
	 * @var obj
	 */
	var $obj_system_power;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $obj_validate;
	
	function main(){
		/**
		 * 创建权限对象
		 */
		if (!is_object($this->obj_system_power)){
			require_once("system_power.class.php");
			$this->obj_system_power = new SystemPowerClass();
		}		
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->obj_validate)){
			require_once("commonvalidate.class.php");
			$this->obj_validate = new CommonValidate();
		}
		
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");

		/**
		 * 语言包
		 */
		$this->getlang("system_power");
		
		switch ($this->_input['action']){
			case "add_group":
				$group_case = 'add_group';
				$this->_add_group($group_case);
				break;
			case "save_group":
				$this->_save_group();
				break;
			case "modi_group":
				$group_case = 'modi_group';
				$this->_modi_group($group_case);
				break;
			case "update_group":
				$this->_update_group();
				break;
			case "del_group":
				$this->_del_group();
				break;
			case "member":	
				$this->_list_member();
				break;
			case "add_member":
				$member_case = 'add_member';
				$this->_add_member($member_case);
				break;
			case "save_member":
				$this->_save_member();
				break;
			case "modi_member":
				$member_case = 'modi_member';
				$this->_modi_member($member_case);
				break;
			case "update_member":
				$this->_update_member();
				break;
			case "del_member":
				$this->_del_member();
				break;
			case "log":
				$this->_list_log();
				break;
			case "list_group":
				$this->_list_group();
				break;
			default:
				$this->_list_group();
				break;
		}
	}
	
	/**
	 * 后台权限管理 首页
	 */
	function _list_group(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		
		/**
		 * 获得列表
		 */
		$obj_page->pagebarnum(10);
		$sys_group_list = $this->obj_system_power->getSystemGroupList('',$obj_page);
		$page_list = $obj_page->show(1);
		
		/**
		 * 页面输出
		 */
		$this->output('sys_group_list',$sys_group_list);
		$this->output('page_list',$page_list);
		$this->showpage('sys_system_power.manage');
	}
	
	/**
	 * 添加权限组
	 */
	function _add_group($group_case){
		/**
		 * 栏目列表
		 */
		$this->publicModule();
		
		/**
		 * 页面输出
		 */
		$this->output('group_case',$group_case);
		$this->showpage('sys_system_power_group.add');
	}
	
	/**
	 * 添加保存权限组
	 */
	function _save_group(){
		
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_group_name"], "require"=>"true", "message"=>$this->_lang['errSysGroupName']));
		$error = $this->obj_validate->validate();
		if($error != ""){
			echo $error;
			exit;
		}
		
		/**
		 * 添加
		 */
		$this->obj_system_power->addSysGroup($this->_input);
		echo 'ok';exit;	
	}
	
	/**
	 * 修改权限组
	 */
	function _modi_group($group_case){
		
		$sys_group_id = $this->_input['sys_group_id'];
		$group_array = $this->obj_system_power->getSysGroupById($sys_group_id);
		
		/**
		 * 页面输出
		 */
		$this->output('group_case',$group_case);
		$this->output('group_array',$group_array);
		$this->showpage('sys_system_power_group.add');
	}
	
	/**
	 * 保存修改权限组
	 */
	function _update_group(){
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_group_name"], "require"=>"true", "message"=>$this->_lang['errSysGroupName']));
		$error = $this->obj_validate->validate();
		if($error != ""){
			echo $error;
			exit;
		}
		
		/**
		 * 更新
		 */
		$this->obj_system_power->updateSysGroup($this->_input);
		echo 'ok';exit;	
	}
	
	/**
	 * 删除权限组
	 */
	function _del_group(){
		
		/**
		 * 判断是否权限组下还有成员
		 */
		if (is_array($this->_input['sys_group_id'])){
			foreach ($this->_input['sys_group_id'] as $value){
				$condition['sys_group_id'] = $value;
				$condition['order_group_id'] = 1;
				$sys_member_list = $this->obj_system_power->getSystemMemberList($condition,$obj_page);
				if (!empty($sys_member_list)){
					$group_array = $this->obj_system_power->getSysGroupById($value);
					$error .= $group_array['sys_group_name']."下还有成员<br/>";
				}
				unset($condition);
			}
			if ($error != ""){
				echo $error;
				exit;
			}
			/**
			 * 删除权限组
			 */
			$this->obj_system_power->delSysGroup($this->_input['sys_group_id']);
			echo 'ok';exit;
		}
		
		
	}
	
	/**
	 * 管理员列表
	 */
	function _list_member(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		
		/**
		 * 获得列表
		 */
		$obj_page->pagebarnum(10);
		$condition['sys_group_id'] = $this->_input['sys_group_id'];
		$condition['order_group_id'] = 1;
		$sys_member_list = $this->obj_system_power->getSystemMemberList($condition,$obj_page);
		/**
		 * 取管理员所在权限组
		 */
		if (is_array($sys_member_list)){
			foreach ($sys_member_list as $key => $value){
				$group_array = $this->obj_system_power->getSysGroupById($value['sys_group_id']);
				$sys_member_list[$key]['sys_group_name'] = $group_array['sys_group_name'];
			}
		}
		
		$page_list = $obj_page->show(1);
		
		/**
		 * 页面输出
		 */
		$this->output('sys_member_list',$sys_member_list);
		$this->output('page_list',$page_list);
		$this->showpage('sys_system_power_member.manage');
	}
	
	/**
	 * 添加管理员
	 */
	function _add_member($member_case){
		/**
		 * 权限组列表
		 */
		$sys_group_list = $this->obj_system_power->getSystemGroupList('',$obj_page);
		
		/**
		 * 页面输出
		 */
		$this->output('member_case',$member_case);
		$this->output('sys_group_list',$sys_group_list);
		$this->showpage('sys_system_power_member.add');
	}
	
	/**
	 * 保存添加管理员
	 */
	function _save_member(){
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_login_name"], "require"=>"true", "message"=>$this->_lang['errMloginname']),
		array("input"=>$this->_input["sys_login_name"], "validator"=>"Length", "min"=>"5", "max"=>"20", "message"=>$this->_lang['errWrongUserName']),
		array("input"=>$this->_input["sys_login_name"], "validator"=>"Length", "min"=>"5", "max"=>"20", "message"=>$this->_lang['errWrongUserName']),
		array("input"=>$this->_input["sys_password"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
		array("input"=>$this->_input["sys_password_two"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
		array("input"=>$this->_input["sys_password"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
		array("input"=>$this->_input["sys_password_two"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
		array("input"=>$this->_input["sys_password"], "require"=>"true", "validator"=>"Compare", "operator"=>"==","to"=>$this->_input["sys_password_two"], "message"=>$this->_lang['errMmatchingpassword'],"result"=>true),
		);
		$error = $this->obj_validate->validate();
		if($error != ""){
			echo $error;
			exit;
		}
		
		/**
		 * 添加管理员
		 */
		$sys_group_list = $this->obj_system_power->addSysMember($this->_input);
		echo 'ok';exit;
	}
	
	/**
	 * 修改管理员
	 */
	function _modi_member($member_case){
		
		/**
		 * 取管理员信息
		 */
		$sys_member_id = $this->_input['sys_member_id'];
		$member_array = $this->obj_system_power->getSysMemberById($sys_member_id);
		
		/**
		 * 权限组列表
		 */
		$sys_group_list = $this->obj_system_power->getSystemGroupList('',$obj_page);
		
		/**
		 * 页面输出
		 */
		$this->output('member_case',$member_case);
		$this->output('member_array',$member_array);
		$this->output('sys_group_list',$sys_group_list);
		$this->showpage('sys_system_power_member.add');
	}
	
	/**
	 * 保存更新管理员
	 */
	function _update_member(){

		/**
		 * 验证接收变量
		 */
		if ($this->_input["sys_password"] != "" || $this->_input["sys_password_two"] != ""){
			$this->obj_validate->validateparam = array(
			array("input"=>$this->_input["sys_password"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
			array("input"=>$this->_input["sys_password_two"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
			array("input"=>$this->_input["sys_password"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
			array("input"=>$this->_input["sys_password_two"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
			array("input"=>$this->_input["sys_password"], "require"=>"true", "validator"=>"Compare", "operator"=>"==","to"=>$this->_input["sys_password_two"], "message"=>$this->_lang['errMmatchingpassword'],"result"=>true),
			);
			$error = $this->obj_validate->validate();
			if($error != ""){
				echo $error;
				exit;
			}
		}
		/**
		 * 添加
		 */
		$this->obj_system_power->updateSysMember($this->_input);
		echo 'ok';exit;	
	}
	
	/**
	 * 删除管理员
	 */
	function _del_member(){
		
		$this->obj_system_power->delSysMember($this->_input['sys_member_id']);
		echo 'ok';exit;
	}
	
	/**
	 * 添加管理日志
	 */
	function _add_log($log){
		
		$this->_input['sys_member_id'] = $_SESSION['s_admin']['id'];
		$this->_input['sys_login_name'] = $_SESSION['s_admin']['name'];
		$this->_input['sys_log_note'] = $log;
		$this->_input['sys_log_time'] = time();
		
		$this->obj_system_power->addSysLog($this->_input);
		
	}
	
	/**
	 * 管理员日志
	 */
	function _list_log(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();
		
		/**
		 * 获得列表
		 */
		$obj_page->pagebarnum(10);
		if ($this->_input['sys_member_id'] != ""){
			$condition['sys_member_id'] = $this->_input['sys_member_id'];
		}
		$condition['order_log_id'] = 1;
		$sys_log_list = $this->obj_system_power->listSysLog($condition,$obj_page);	
		$page_list = $obj_page->show(1);
		
		/**
		 * 页面输出
		 */
		$this->output('page_list',$page_list);
		$this->output('sys_log_list',$sys_log_list);
		$this->showpage('sys_system_log.manage');
	}
	
}

$system_power = new SysPowerManage();
$system_power->main();
unset($system_power);
?>